<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015/12/19
 * Time: 14:40
 */
class Activity_vote_user_model extends CI_Model
{
    private $_table = 'activity_vote_user';

    /**
     * 根据ip来查找用户
     * @param $ip
     * @return mixed
     */
    public function findByIp($ip, $voteId,$type=1,$uid)
    {
        $this->db->select('id');
        $this->db->from($this->_table);
        if ($type==2) {
            $this->db->where('uid',$uid);
        } else {
            $this->db->where('ip', $ip);
        }
        $this->db->where('vote_id', $voteId);
        $this->db->where('date', date('Y-m-d'));
        $this->db->limit(1);

        return $this->db->get();
    }

    /**
     * 根据uid来判断用户是否投过票
     * @param $uid
     * @return mixed
     */
    public function findByUid($uid, $voteId)
    {
        $this->db->select('id');
        $this->db->from($this->_table);
        $this->db->where('uid', $uid);
        $this->db->where('vote_id', $voteId);
        $this->db->where('date', date('Y-m-d'));
        $this->db->limit(1);

        return $this->db->get();
    }

    /**
     * 添加
     * @param $postData
     * @return mixed
     */
    public function insertVoteUser($postData)
    {
        $data = array(
            'vote_id'    => $postData['vote_id'],
            'ip'         => $postData['ip'],
            'uid'        => $postData['uid'],
            'date'       => date('Y-m-d'),
            'details'    => $postData['details'],
            'created_at' => date('Y-m-d H:i:s')
        );

        return $this->db->insert($this->_table, $data);
    }



}